﻿using System;

class Matrix
{
    private int[,] matrix;  // pole na klasa -> prez nego se zapisvat dannite

    public Matrix(int rows, int cols)    // konstruktor4e, koeto suzdava po zadaden princip obekt ot klasa
    {
        this.matrix = new int[rows, cols];
    }

    public int Rows // svoistvo na poleto, v tozi slu4ai -> da ima redove
    {
        get // get metod4e s cel da otbelejim ot kude 6te vzemem stoinostta za svoistvoto
        {
            return this.matrix.GetLength(0);
        }
    }
    public int Columns  // o6te edno svoistvo
    {
        get
        {
            return this.matrix.GetLength(1);
        }
    }

    public static Matrix operator +(Matrix first, Matrix second)
    {
        Matrix result = new Matrix(first.Rows, second.Columns);
        for (int row = 0; row < first.Rows; row++)
        {
            for (int col = 0; col < first.Columns; col++)
            {
                result[row, col] = first[row, col] + second[row, col];
            }
        }
        return result;
    }

    public static Matrix operator -(Matrix first, Matrix second)
    {
        Matrix result = new Matrix(first.Rows, second.Columns);
        for (int row = 0; row < first.Rows; row++)
        {
            for (int col = 0; col < first.Columns; col++)
            {
                result[row, col] = first[row, col] - second[row, col];
            }
        }
        return result;
    }
    public static Matrix operator *(Matrix first, Matrix second)
    {
        Matrix result = new Matrix(first.Rows, second.Columns);
        for (int row = 0; row < first.Rows; row++)
        {
            for (int col = 0; col < first.Columns; col++)
            {
                result[row, col] = first[row, col] * second[row, col];
            }
        }
        return result;
    }

    public int this[int row, int col]   // 4rez tova 6te mojem da dostupvame matricata po indexi.
    {
        get
        {
            return this.matrix[row, col];
        }
        set
        {
            this.matrix[row, col] = value;  // pokazvame, 4e 4rez skobite i promenlivite vutre 6te podavam stoinost (value)
        }
    }

    public override string ToString()
    {
        string result = null;
        for (int row = 0; row < this.Rows; row++)
        {
            for (int col = 0; col < this.Columns; col++)
            {
                result += matrix[row, col] + " ";   // Console.Write(matrix[row,col] + " ");
            }
            result += Environment.NewLine;  // Console.WriteLine();
        }
        return result;
    }
}
